<?php
MYTCONN();
$BlStatus = '';
if (isset($_GET['AMLID'])) {
    $OB_AML = $_GET['AMLID'];
} else {
    $OB_AML = $_POST['amh_ID'];
}
$GET = $GLOBALS['MYT']->db_array("SELECT CONCAT(FraOrigen0,'-',FraReferenciaAg) AS amh_COL5,
  						amh_Operacion, amh_ID, sttFlag, amh_Fecha, amh_Status, amd_Desc, FraCliNumero, REPORT,
						stt_Word, amh_Comentario, FraStatus, amh_Reply,
						hd_amllocks.REF, LEVEL, INTERV, AMOUNT, QUANT, DOCS
					FROM hd_amlalertas
					INNER JOIN hd_amldetalle ON hd_amldetalle.amd_Alerta = hd_amlalertas.amh_ID
					INNER JOIN hd_amllocks ON hd_amllocks.REF  = amh_levelid
					INNER JOIN facturas ON FraID = amh_Operacion
  					INNER JOIN hd_sysstatus ON hd_sysstatus.sttFlag = hd_amldetalle.amd_CODE AND stt_Sistema = 12
					WHERE amh_ID = $OB_AML");
if (!isset($GET[1])) {
    die("Error:DB");
}
//=====================Invoice Form=========================
mn_field('hidden', 'ED', 'amh_Operacion', $GET[1]['amh_Operacion'], '', '', '', '');
?>

<div id="AMLOrderAction"></div>
    <div class="title"> Alerta
    <?php 
    mn_field('text', 'ED', 'amh_ID', $GET[1]['amh_ID'], '', '', '', 'NUMBER" readonly="');
    echo ' | ';
    mn_field('button', 'ED', 'PRAML', 'Salvar', '', '', '', 'SUBMIT" onclick="
		document.MQuery.action=\'_response/call.php?get=Compliance/cpl_editalert\';
		subform(\'MQuery\',\'SaveAML\');');
    echo ' | ';
    mn_field('button', 'ED', 'PrintReport', 'Imprimir Formulario de Compliance', '', '', '', '" onclick="
		newprint(\'Aplications/Export_Print?MOD=COMPLIANCE&ID=01&OB=' . $GET[1]['amh_ID'] . '\',\'Printer\');'); ?>
        <div id="SaveAML" style="float:right"></div>
    </div>
<table width="98%"  border="0" cellpadding="3" cellspacing="0" bgcolor="#F7F7F4">

    <tr>
        <td valign="top"><table cellpadding="2" cellspacing="2">
                <tr>
                    <td>Remessa:
<?php
            echo $GET[1]['amh_Operacion'] . ' | <b>' . $GET[1]['amh_COL5'] . '</b></br>';
            if ($GET[1]['amh_Status'] != '1') {
                mn_field('hidden', 'ED', 'ConfBlock', '1', '', '', '', '');
            }
            if (substr($SESSST, 1, 1) != 'A') {
                $BlStatus = " AND sttFlag = '{$GET[1]['amh_Status']}'";
                if ($GET[1]['sttFlag'] == 121 && $GET[1]['FraStatus'] == 14) {
                    $BlStatus = '';
                    mn_field('hidden', 'ED', 'ConfBlock', '1', '', '', '', '');
                }
            }
?></td>
                </tr>
                <tr>
                    <td colspan="3"><?php echo $GET[1]['sttFlag'] . ' - ' . $GET[1]['stt_Word']; ?></td>
                </tr>
                <tr>
                    <td colspan="3">Data do Alerta :
<?php echo $GET[1]['amh_Fecha']; ?>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <div class="Line"><b>Nível de Bloqueio</b><br>
<?php echo ' ID: ' . $GET[1]['REF'] . ', Nível: ' . $GET[1]['LEVEL'] . ', Periodo: ' . $GET[1]['INTERV'] . '<br>Valor: ' . $GET[1]['AMOUNT'] . ' Quantidade de Remessas: '.($GET[1]['QUANT']+1);?></div></td>
                </tr>
                <tr>
                    <td>Data do Alerta : </td>
                    <td colspan="2"><?php echo $GET[1]['amh_Fecha']; ?></td>
                </tr>
                <tr>
                    <td>Estado: </td>
                    <td colspan="2"><?php
                            $SearchStatus = "SELECT sttFlag AS ID, stt_Word AS NAME FROM hd_sysstatus WHERE stt_Sistema = 14 {$BlStatus}";
                            mn_field('select', 'ED', 'amh_Status', $GET[1]['amh_Status'], $SearchStatus, '', 'False', 'inputbox');
?></td>
                    </tr>
                </table>
<?php if (substr($SESSST, 1, 1) == 'A') {?>
   Resposta<br>
<?php mn_field('textarea', 'ED', 'amh_Reply', $GET[1]['amh_Reply'], '48', '3', '', ''); ?>
                                <br>Observações<br>
<?php mn_field('textarea', 'ED', 'amh_Comentario', $GET[1]['amh_Comentario'], '48', '3', '', '');
                            } ?></td>
                        <td valign="top">

                            <div id="DocView"><?php include('amh_doclist.php'); ?></div>
                        </td>
                    </tr>
                </table>
<?php
                            if (isset($_GET['RSID']) && strlen($_GET['RSID']) > 0 || strlen($GET[1]['amd_Desc']) > 0) {
                                $AMLORDSEP = ',';
                            } else {
                                $AMLORDSEP = '';
                            }
                            if (isset($_GET['RDOB'])) {
                                $AMLORD = $_GET['RDOB'] . $AMLORDSEP . str_replace(';', ',', $_GET['RSID']);
                            } else {
                                $AMLORD = $GET[1]['amh_Operacion'] . $AMLORDSEP . str_replace(';', ',', $GET[1]['amd_Desc']);
                            }
                            $Qr_rs = $GLOBALS['MYT']->db_array("SELECT 
    FraID AS O_ID, FraFechaIngreso AS COL1, FraEnviado AS COL4, FraCargo AS COL7, FraCliNombre COL2,
    FraBnfNombre AS COL3, CONCAT(FraOrigen0,'-',FraReferenciaAg) AS COL5, sg_Descripcion AS COL6
        FROM facturas
    INNER JOIN facturasextjoins ON FraID = FraExtID
    INNER JOIN hd_statusfacturas ON sg_ID = FraStatus
    WHERE FraID IN ($AMLORD)");
    $CARD = $Qr_rs[0];
    $SUM = 0;
    $str = '';
    for ($i = 1; $i <= $CARD; $i++) {
        $SUM += $Qr_rs[$i]['COL4'] + $Qr_rs[$i]['COL7'];
        $str .= '[' . $i . ',' . $Qr_rs[$i]['O_ID'] . ',\'' . $Qr_rs[$i]['COL1'] . '\',\'' . req_form($Qr_rs[$i]['COL2']) . '\',\'' . $Qr_rs[$i]['COL3'] . '\',\'' . number_format($Qr_rs[$i]['COL4'], 2, ',', '') . '\',\'' . $Qr_rs[$i]['COL5'] . '\',\'' . $Qr_rs[$i]['COL6'] . '\',\'' . number_format($Qr_rs[$i]['COL7'], 2, ',', '') . '\'],';
    }
?>
<div id="AMLOrderList"></div>
<script charset="utf-8" type="text/javascript">
    disableSelection(document.getElementById("AMLOrderList"));
    Ext.onReady(function(){      

        var myData = [<?php echo substr($str, 0, strlen($str) - 1); ?>];

        var ds = new Ext.data.Store({
            reader: new Ext.data.ArrayReader({}, [
                {name: 'id'},
                {name: 'O_ID', type: 'int'},
                {name: 'COL1', type: 'string'},
                {name: 'COL2', type: 'string'},
                {name: 'COL3', type: 'string'},
                {name: 'COL4', type: 'string'},
                {name: 'COL5', type: 'string'},
                {name: 'COL6', type: 'string'},
                {name: 'COL7', type: 'string'}
            ])
        });
        ds.loadData(myData);
        var colModel = new Ext.grid.ColumnModel([
            {header: "N", width: 40, sortable: true, locked:true, dataIndex: 'id'},
            {header: "Operacao", width: 60, sortable: true, locked:true, dataIndex: 'O_ID'},
            {header: "Remessa", width: 70, sortable: true, locked:true, dataIndex: 'COL5'},
            {header: "Data", width: 120, sortable: true, locked:true, dataIndex: 'COL1'},
            {header: "Remetente", width: 200, sortable: true, dataIndex: 'COL2'},
            {header: "Destinatario", width: 200, sortable: true, locked:true,dataIndex: 'COL3'},
            {header: "Montante", width: 100, sortable: true, align:'right', locked:true,dataIndex: 'COL4'},
            {header: "Taxa", width: 80, sortable: true, align:'right', locked:true,dataIndex: 'COL7'},
            {header: "Estado", width: 130, sortable: true, align:'right', locked:true,dataIndex: 'COL6'}
        ]);


        Bars = new Ext.Toolbar({

            store: this.store,
            height: 25,
            align: 'right',
            items : [ {
                    text: "# <?php echo $CARD; ?> | EUR: <?php echo number_format($SUM, 2); ?>"
                } ]
        });

        function ShowProp(id) {
            var properties = new Ext.Window({
                title:'Detalhes e previsualizacao',
                autoLoad: '_response/call.php?get=Operative/frm_transferdetails&RSID='+id,
                modal:true,
                width:680,
                height:500
                });
            properties.show();
        }

        var selmode = new Ext.grid.RowSelectionModel({});
        var Console = new Ext.grid.GridPanel({
            ds: ds,
            cm: colModel,
            sm: selmode,
            listeners: {
                rowdblclick: function(ds, row) {
                    var record = ds.getStore().getAt(row);
                    var value = record.get('O_ID');
                    ShowProp(value);
                    //menuwindow('Operativo','Modules/CLDJ49SJ/pp_frm?OR='+value,800,520,'MnMain');
                }
            },
            height: 160,
            bbar: Bars,
            renderTo: 'AMLOrderList'
        });

    });
</script>